package cmd

import (
	"context"

	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/app"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/component"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/employee"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/license"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/menu"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/organization"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/permission"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/region"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/role"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/tenant"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/user"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/controller/usergroup"
	"gitee.com/liangziyisheng/caas-platform-mc/utility/authentication"
	"gitee.com/liangziyisheng/caas-platform-mc/utility/authorization"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var gfToken = authentication.NewToken()
var (
	Main = gcmd.Command{
		Name:  "MC",
		Usage: "管理中心",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/api", func(group *ghttp.RouterGroup) {
				group.Middleware(ghttp.MiddlewareCORS)
				gfToken.Middleware(ctx, group)
				// 校验token
				// group.Middleware(ValidToken)
				group.Middleware(authorization.CasbinMiddleware)
				group.Middleware(ghttp.MiddlewareHandlerResponse)
				group.Group("/mc", func(gps *ghttp.RouterGroup) {
					gps.Group("/tmo", func(gpt1 *ghttp.RouterGroup) {
						gpt1.Bind(
							tenant.NewV1(),
							license.NewV1(),
						)
					})
					gps.Group("/apm", func(gpt2 *ghttp.RouterGroup) {
						gpt2.Bind(
							component.NewV1(),
							app.NewV1(),
							menu.NewV1(),
							permission.NewV1(),
							role.NewV1(),
						)
					})
					gps.Group("/cam", func(gpt3 *ghttp.RouterGroup) {
						gpt3.Bind(
							user.NewV1(),
							usergroup.NewV1(),
						)
					})
					gps.Group("/edm", func(gpt4 *ghttp.RouterGroup) {
						gpt4.Bind(
							region.NewV1(),
						)
					})
					gps.Group("/mdm", func(gpt4 *ghttp.RouterGroup) {
						gpt4.Bind(
							organization.NewV1(),
							employee.NewV1(),
						)
					})
				})

			})
			s.Run()
			return nil
		},
	}
)
